#!/usr/bin/env python3

"""
一个函数依赖执行其他函数执行的结果执行,因此需要一个列表存储其他函数(注册)
如果手动添加新函数策略,可能会因为遗漏导致出错,所以使用装饰器功能
"""

class FuncRegister(object):

    def __init__(self, promos):
        self.promos = promos

    #  def __new__(cls):
        #  if not cls.promos:
            #  cls.promos = object.__new__(cls)
        #  return cls.promos

    def __call__(self, func):
        return self.promotion(func)

    def promotion(self, func):
        self.promos.append(func)
        return func

promos = []
func_reg = FuncRegister(promos)

@func_reg
def f4(order):
    return order * .07


#  @promotion
#  def f1(order):
    #  return order * .05

#  @promotion
#  def f2(order):
    #  return order * .06

#  @promotion
#  def f3(order):
    #  return order * .07

#  def best_f(order):
    #  return max(promo(order) for promo in promos)

#  import deco_exec

#  @deco_exec.register
#  def hello():
    #  print("hello, this is register")

if __name__ == "__main__":
    order = 100
    #  res = best_f(order)
    #  print(res)
    #  hello()
    #  print(deco_exec.res)
    res = f4(order)
    print(func_reg.promos)
